﻿#region Creditos

/* Autor: Edilberto Sánchez Forero	*/
/* Email: esanchezfo@gmail.com		*/
/* Licencia: LGPL, Software Libre	*/
/* País: Colombia, Bogotá			*/

#endregion

#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESF.Peer.Handlers;
using Ciatel.ISO8583.Amex;
using System.Net;
using ESF.SSO.Core.Entities;
using ESF.SSO.ISO8583.ClientRequestHandler.Operations;
using ESF.General;
using System.Net.Sockets;

#endregion


namespace ESF.SSO.ISO8583.ClientRequestHandler
{
	public class SSORequestHandler : IRequestHandler<Message>
	{
		#region Constantes
		
		public const string Client_BIN = "255975";
		public const int PASSWORD_LENGTH = 4;
		
		#endregion
		
		
		#region Miembros de IRequestHandler<Message>

		public void ProcessRequests(List<Message> pRequests, IPEndPoint pSenderIPEndPoint, IPEndPoint pForwarderIPEndPoint, out List<Message> pResponses, out string pEventCode, out string pEventName, out List<object> pProcessedObjects)
		{
			SSOISO8583Operations code;
			
			
			code = (SSOISO8583Operations) pRequests [0].ApplicationData.DataElements.GetCustomProcessingCode ();
			
			pEventCode = Convert.ToInt32 (code).ToString ();
			pEventName = code.ToString ();
			
			pResponses = null;
			
			switch (code)
			{
				case SSOISO8583Operations.SignIn:
					SignIn.ProcessRequest (pRequests, pSenderIPEndPoint, pForwarderIPEndPoint, out pProcessedObjects);
				break;
				
				case SSOISO8583Operations.SignIn_I:
					SignIn_I.ProcessRequest (pRequests, pSenderIPEndPoint, pForwarderIPEndPoint, out pProcessedObjects);
				break;
				
				case SSOISO8583Operations.CloseSession:
					CloseSession.ProcessRequest (pRequests, pSenderIPEndPoint, pForwarderIPEndPoint, out pProcessedObjects);
				break;
				
                //case SSOISO8583Operations.GetList:
                //    GetList.ProcessRequest (pRequests, pSenderIPEndPoint, pForwarderIPEndPoint, out pProcessedObjects);
                //break;
				
				case SSOISO8583Operations.GetList_I:
					GetList_I.ProcessRequest (pRequests, pSenderIPEndPoint, pForwarderIPEndPoint, out pProcessedObjects);
				break;
				
				case SSOISO8583Operations.GetMenuImages:
					GetUserMenuImages.ProcessRequest (pRequests, pSenderIPEndPoint, pForwarderIPEndPoint, out pProcessedObjects);
				break;
				
				default:
					throw new GenericException (ISO8583Exception.RequestedFunctionNotSupported, string.Format ("The operation {0}({1}) is not suppported", pEventName, pEventCode));
			}
		}

		#endregion
	}
}